import request from '/@/utils/request';


//获取分页列表
export function getList(params: object) {
	return request({
		url: '/QuestTags/getList',
		method: 'post',
		data: params,
	});
}

//获取全部菜单列表
export function getListAll(params: any) {
	return request({
		url: '/QuestTags/getlists',
		method: 'post',
		data: params,
	});
}



//获取详情
export function getinfo(id: String) {
	return request({
		url: '/QuestTags/getinfo',
		method: 'post',
		data: { id },
	});
}

   
//保存
export function save(params: object) {
	return request({
		url: '/QuestTags/save',
		method: 'post',
		data: params,
	});
}

export function all(params: object) {
	return request({
		url: '/Chapter/all',
		method: 'post',
		data: params,
	});
}

export function getListsss(params: object) {
  return request({
		url: '/Chapter/getList',
		method: 'post',
		data: params,
	});
}
//删除
export function del(id: String) {
	return request({
		url: '/QuestTags/del',
		method: 'post',
		data: { id },
	});
}
  
//改变字段值
export function edit(params:object) {
	return request({
		url: '/QuestTags/edit',
		method: 'post',
		data:params
	})
}
// 获取题目分页列表
export function getQuestionList(params: {
    subject_id?: number;
    chapter_id?: number;
    question_type?: number;
    keyword?: string;
    page?: number;
    size?: number;
  }) {
    return request({
      url: '/question/index',
      method: 'get',
      params,
    });
  }
  
  // 删除题目
  export function deleteQuestion(id: string) {
    return request({
      url: `/question/delete`,
      method: 'post',
      data:id
    });
  }
  

  // 获取科目列表
  export function getSubjects() {
    return request({
      url: '/index/subject',
      method: 'get',
    });
  }
  
  //新
  // 获取章节树形结构
  export function getChapterTree(params:string) {
    return request({
      url: '/index/chapterTree',
      method: 'post',
      data:params
    });
  }
  
  // 获取题目详情
  export function getQuestionDetail(id: string) {
    return request({
      url: `/question/read`,
      method: 'get',
      params:id
    });
  }
  
  // 创建题目
  export function createQuestion(data: {
    subject_id: number;
    chapter_id?: number;
    question_type: number;
    difficulty?: number;
    content: string;
    answer: string;
    analysis?: string;
    score?: number;
    options?: Array<{
      option_key: string;
      option_content: string;
      is_correct?: number;
    }>;
  }) {
    return request({
      url: '/question/save',
      method: 'post',
      data,
    });
  }
  
  // 更新题目
  export function updateQuestion(id: string, data: {
    subject_id: number;
    chapter_id?: number;
    question_type: number;
    difficulty?: number;
    content: string;
    answer: string;
    analysis?: string;
    score?: number;
    options?: Array<{
      option_key: string;
      option_content: string;
      is_correct?: number;
    }>;
  }) {
    return request({
      url: `/question/update`,
      method: 'post',
      data,
    });
  }
  
  // 批量导入题目
  export const batchCreateQuestions = (data: {
    questions: Array<{
      subject_id?: number;
      chapter_id?: number;
      question_type: number;
      difficulty?: number;
      content: string;
      answer: string;
      analysis?: string;
      score?: number;
      options?: Array<{
        option_key: string;
        option_content: string;
        is_correct?: number;
      }>;
    }>;
    default_subject_id?: number;
  }) => {
    return request({
        url: `/question/batchSave`,
        method: 'post',
        data,
      });
   
  };
  
  // 下载模板
  export const downloadTemplate = () => {
    return axios.get('/question/template', {
      responseType: 'blob'
    });
  };